from typing import Dict, Any
from langgraph.graph import StateGraph
from langgraph.checkpoint.memory import MemorySaver


def build_main_graph():
    graph = StateGraph(dict)

    def node_interact(state: Dict[str, Any]) -> Dict[str, Any]:
        return {**state, "interact": True}

    def node_intent(state: Dict[str, Any]) -> Dict[str, Any]:
        return {**state, "intent": "gate_query"}

    def node_service(state: Dict[str, Any]) -> Dict[str, Any]:
        return {**state, "service": {"gate": "A12"}}

    graph.add_node("interact", node_interact)
    graph.add_node("intent", node_intent)
    graph.add_node("service", node_service)
    graph.add_edge("interact", "intent")
    graph.add_edge("intent", "service")
    graph.set_entry_point("interact")

    memory = MemorySaver()
    app = graph.compile(checkpointer=memory)
    return app